home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / util / misc / gadmget2.lha / GadMget / GadMGet.source.lha / mget_listview2.c < prev    next >
C/C++ Source or Header  |  1995-07-30  |  22KB  |  740 lines

  1. #ifndef MGET_LISTVIEW2_C
  2. #define MGET_LISTVIEW2_C
  3.  
  4. /*
  5.  *  Source machine generated by GadToolsBox V2.0b
  6.  *  which is (c) Copyright 1991-1993 Jaba Development
  7.  *
  8.  *  GUI Designed by : Jeremy Friesner
  9.  */
  10.  
  11. #include <exec/types.h>
  12. #include <exec/libraries.h>
  13. #include <intuition/intuition.h>g
  14. #include <intuition/classes.h>
  15. #include <intuition/classusr.h>
  16. #include <intuition/imageclass.h>
  17. #include <intuition/gadgetclass.h>
  18. #include <libraries/gadtools.h>
  19. #include <graphics/displayinfo.h>
  20. #include <graphics/gfxbase.h>
  21. #include <clib/exec_protos.h>
  22. #include <clib/intuition_protos.h>
  23. #include <clib/gadtools_protos.h>
  24. #include <clib/graphics_protos.h>
  25. #include <clib/utility_protos.h>
  26. #include <clib/wb_protos.h>
  27.  
  28. #include <workbench/workbench.h>
  29. #include <workbench/startup.h>
  30. #include <string.h>
  31.  
  32. #include "mget_listview2.h"
  33. #include "Gadmget.h"
  34.  
  35. #define BACKSPACE_KEYCODE 8
  36. #define UP_KEYCODE        76
  37. #define DOWN_KEYCODE      77
  38. #define LEFT_KEYCODE      79
  39. #define RIGHT_KEYCODE     78
  40.  
  41. extern char pnamestring[];
  42. extern struct List *filelist;
  43. extern struct List *getlist;
  44. extern struct Gadget *findgadlist;
  45. extern void *findvi;
  46. extern int appwindow;
  47. extern char *pubscreenname;
  48. extern int screentype;
  49. extern UWORD windowwidth;
  50. extern UWORD windowheight;
  51. extern UWORD windowtop;
  52. extern UWORD windowleft;
  53. extern char windowtitle[];
  54. extern int windowisopen;
  55. extern int screenisopen;
  56. extern char sListFontName[];
  57. extern char sOutFileName[];
  58. extern int nListFontSize;
  59. extern FILE *fpOut;
  60. extern struct TextFont *listfontdata;  /* pointer to font data */
  61. extern struct GfxBase *GraphicsBase;   /* needed to determine default system font */
  62. extern BOOL BStartedFromWB;
  63. extern int nTopListTop;
  64. extern int nTopListHeight;
  65. extern int nBottomListHeight;
  66. extern int filelist_length;
  67. extern int getlist_length;
  68.     
  69. int screenwidth,screenheight;
  70.  
  71. struct Screen        *Scr = NULL;
  72. APTR                 VisualInfo = NULL;
  73. struct Window        *mgetWnd = NULL;
  74. struct Window           *findwindow = NULL;
  75. struct AppWindow     *appwin = NULL;
  76. struct AppMessage    *amsg = NULL;
  77. struct MsgPort          *awport = NULL;
  78. struct Gadget        *mgetGList = NULL;
  79. struct Menu          *mgetMenus = NULL;
  80. struct IntuiMessage  mgetMsg;
  81. struct Gadget        *mgetGadgets[2];
  82. UWORD                mgetLeft = 0;
  83. UWORD                mgetTop = 12;
  84. UWORD lastcode;
  85. ULONG appwinsig = 0L;
  86.  
  87. /* If non-negative, these were the pre-iconify values */
  88. int nPrevLeft = -1, nPrevTop = -1, nPrevWidth = -1, nPrevHeight = -1;
  89.  
  90. struct TextAttr topaz8 = {
  91.     ( STRPTR )"topaz.font", 8, 0x00, 0x00 };
  92.  
  93. struct TextAttr listfont = {
  94.     NULL, 0 , 0x00, 0x00 };
  95.  
  96. /* Used right-amiga key letters:
  97.  
  98. out of: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  99. used:   ABCDEFG IJKLMNOPQRSTUVWXY
  100.  
  101. */
  102. struct NewMenu mgetNewMenu[] = {
  103.  NM_TITLE, "Project",         NULL,     0L,      NULL, NULL,
  104.  NM_ITEM, "Open...",         "O",     0L,      0L, (APTR)mgetopenfile,
  105.  NM_ITEM, "Append",         "A",     0L,      0L, (APTR)mgetappend,
  106.  NM_ITEM, "Save",        "S",    0L,     0L, (APTR)mgetsave, 
  107.  NM_ITEM, "Save As...",        "W",    0L,     0L, (APTR)mgetsaveas, 
  108.  NM_ITEM, "Clear",                 NULL,     0L,      NULL, NULL,
  109.  NM_SUB,  "Files List",           "U",      0L,      0L, (APTR)mgetclearfiles,
  110.  NM_SUB,  "Get List",             "G",      0L,      0L, (APTR)mgetclearget,
  111.  NM_ITEM, "About",         NULL,     0L,      0L, (APTR)mgetabout,
  112.  NM_ITEM, (STRPTR)NM_BARLABEL,     NULL,     0L,      0L, NULL,
  113.  NM_ITEM, "Iconify",        "I",     0L,      0L, (APTR)mgeticonify,
  114.  NM_ITEM, "Output & Quit",     "X",     0L,      0L, (APTR)mgetquit,
  115.  NM_ITEM, "Save & Quit",    "E",     0L,      0L, (APTR)mgetmarkexit,
  116.  NM_ITEM, "Quit",         "Q",     0L,      0L, (APTR)mgetfastquit,
  117.  NM_TITLE,"Find",         NULL,     0L,      NULL, NULL,
  118.  NM_ITEM, "Find Forward",    "F",     0L,      0L, (APTR)mgetfind,
  119.  NM_ITEM, "Find Backward",     "K",     0L,      0L, (APTR)mgetfindback,
  120.  NM_ITEM, "Find from Top",     "T",     0L,      0L, (APTR)mgetfindtop,
  121.  NM_ITEM, "Find from Bottom",     "B",     0L,      0L, (APTR)mgetfindbottom,
  122.  NM_ITEM, "Find Next",         "N",     0L,      0L, (APTR)mgetfindnext,
  123.  NM_ITEM, "Find Previous",     "P",     0L,      0L, (APTR)mgetfindprevious, 
  124.  NM_ITEM, "Find Current",    "J",      0L,     0L, (APTR)mgetfindcurrent,
  125.  NM_ITEM, "Select Multiple",       "M",      0L,     NULL, (APTR)mgetmultiselect,
  126.  NM_ITEM, "Deselect Multiple",    "D",      0L,     NULL, (APTR)mgetmultideselect,
  127.  NM_ITEM, "Case Sensitive",     "C",     CHECKIT, 0L, (APTR)mgetcase,
  128.  NM_TITLE,"Sort",         NULL,     0L,      NULL, NULL,
  129.  NM_ITEM, "Files List",     NULL,     0L,      NULL, NULL,
  130.  NM_SUB,  "By FileName",     "!",     0L,      NULL, (APTR)mgetfilesbyname,
  131.  NM_SUB,  "By Directory",     "@",     0L,      NULL, (APTR)mgetfilesbydir,
  132.  NM_SUB,  "By Size",         "#",     0L,      NULL, (APTR)mgetfilesbysize,
  133.  NM_SUB,  "By Age",        "$",    0L,     NULL, (APTR)mgetfilesbyage,
  134.  NM_SUB,  "By Description",     "%",     0L,      NULL, (APTR)mgetfilesbydesc,
  135.  NM_SUB,  "Keep Sorted",     "-",     CHECKIT, 0L, (APTR) mgetfileskeep,
  136.  NM_ITEM, "Get List",         NULL,     0L,      NULL, NULL,
  137.  NM_SUB,  "By FileName",     "1",     0L,      NULL, (APTR)mgetgetbyname,
  138.  NM_SUB,  "By Directory",     "2",     0L,      NULL, (APTR)mgetgetbydir,
  139.  NM_SUB,  "By Size",         "3",     0L,      NULL, (APTR)mgetgetbysize,
  140.  NM_SUB,  "By Age",        "4",    0L,     NULL, (APTR)mgetgetbyage,
  141.  NM_SUB,  "By Description",     "5",     0L,      NULL, (APTR)mgetgetbydesc,
  142.  NM_SUB,  "Keep Sorted",     "=",    CHECKIT, 0L, (APTR) mgetgetkeep,
  143.  NM_ITEM, "Sort Algorithm",     NULL,     0L,      NULL, NULL,
  144.  NM_SUB,  "Tree Sort",         NULL,     CHECKIT, 0L, (APTR)mgettreesort,
  145.  NM_SUB,  "Bubble Sort",     NULL,     CHECKIT, 0L, (APTR)mgetbubblesort,
  146.  NM_ITEM, "Case Sensitive",     "V",     CHECKIT, 0L, (APTR)mgetsortcase,
  147.  NM_TITLE,"Output",         NULL,     0L,      NULL, NULL,
  148.  NM_ITEM, "Aminet Parse",     NULL,     CHECKIT, 0L, (APTR)mgetnoparse,
  149.  NM_ITEM, "Get Files",         NULL,     CHECKIT, 0L, (APTR)mgetfiles,
  150.  NM_ITEM, "Get Readmes",     NULL,     CHECKIT, 0L, (APTR)mgetreadmes,
  151.  NM_ITEM, "Split Commands",     NULL,     CHECKIT, 0L, (APTR)mgetsplit,
  152.  NM_ITEM, "Simple Paths",     NULL,     CHECKIT, 0L, (APTR)mgetCD,
  153.  NM_ITEM, "Line Length...",     "L",     0,      0L, (APTR)mgetlinelength,
  154.  NM_ITEM, "Output Now",     "Y",     0,      0L, (APTR)mgetoutput,
  155.  NM_ITEM, "Output To...",     "R",     0,      0L, (APTR)mgetoutputfile,
  156.  NM_END,  NULL,         NULL,     0,      0L, NULL };
  157.  
  158. struct NewGadget mgetNGad[] = {
  159.     0, 0, 0, 0, (UBYTE *)"Selectable Files", NULL, 0, PLACETEXT_ABOVE, NULL, (APTR)listviewgadgetClicked,
  160.     0, 0, 0, 0, (UBYTE *)"Selected Files",   NULL, 1, PLACETEXT_BELOW, NULL, (APTR)list2Clicked
  161. };
  162.  
  163. ULONG mgetGTags[] = {
  164.     (GT_Underscore), '_', 
  165.     (TAG_DONE)
  166. };
  167.  
  168. UWORD DriPens[] = {
  169.     ~0 };
  170.  
  171. int SetupScreen( void )
  172. {
  173.     ULONG lflag = 0L;
  174.     struct Screen *sTemp = NULL;
  175.     struct DrawInfo *screen_drawinfo = NULL;
  176.     
  177.     Scr = NULL;
  178.         
  179.     switch (screentype)
  180.         {
  181.         case USE_PUBSCREEN:
  182.             Scr = LockPubScreen(pubscreenname);
  183.             if (Scr == NULL)
  184.                 {
  185.                 MakeReq("Couldn't lock public screen!",NULL,"Huh?"); 
  186.                 return(1L);
  187.                 }
  188.             screenwidth     = Scr->Width;
  189.             screenheight    = Scr->Height;
  190.             break;
  191.             
  192.         case USE_CUSTOMSCREEN:
  193.          if ((sTemp = LockPubScreen("Workbench")) != NULL)
  194.             {
  195.             lflag = GetVPModeID(&(sTemp->ViewPort));    
  196.             screenwidth  = sTemp->Width;
  197.             screenheight = sTemp->Height;
  198.             }
  199.             else
  200.             {
  201.             screenwidth  = 640;
  202.             screenheight = 400;
  203.             lflag = HIRESLACE_KEY;
  204.             }
  205.            
  206.          if (sTemp != NULL) UnlockPubScreen(NULL,sTemp);
  207.             
  208.          if ( ! ( Scr = OpenScreenTags(NULL, 
  209.                 SA_Left,    0,
  210.                 SA_Top,        0,
  211.                 SA_Width,    screenwidth,
  212.                 SA_Height,    screenheight,
  213.                 SA_Depth,    2,
  214.                 SA_Font,    NULL /* &GraphicsBase->DefaultFont */,
  215.                 SA_Type,    CUSTOMSCREEN,
  216.                 SA_DisplayID,    lflag,
  217.                 SA_AutoScroll,    TRUE,
  218.                 SA_Overscan,    OSCAN_TEXT,
  219.                 SA_Pens,    &DriPens[0],
  220.                 SA_Title,    pnamestring,
  221.                 TAG_DONE ))) 
  222.                     return( 1L );
  223.             break;
  224.             
  225.         case USE_WBSCREEN:
  226.             Scr = LockPubScreen("Workbench");
  227.             if (Scr == NULL) {MakeReq("Couldn't lock Workbench Screen!",NULL,"Where is it?"); return(1L);}
  228.             screenwidth = Scr->Width;
  229.             screenheight = Scr->Height;
  230.             break;
  231.         }
  232.         
  233.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  234.         return( 2L );
  235.  
  236.     screenisopen = 1;
  237.     return( 0L );
  238. }
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246. void CloseDownScreen( void )
  247. {
  248.     if ( VisualInfo ) 
  249.         {
  250.         FreeVisualInfo( VisualInfo );
  251.         VisualInfo = NULL;
  252.         }
  253.  
  254.     switch(screentype)
  255.         {
  256.         case USE_CUSTOMSCREEN:
  257.             CloseScreen( Scr );
  258.             Scr = NULL;
  259.             break;
  260.         case USE_PUBSCREEN:
  261.             UnlockPubScreen(NULL,Scr);
  262.             break;
  263.         case USE_WBSCREEN:
  264.             UnlockPubScreen(NULL,Scr);
  265.             break;
  266.         }
  267.     
  268.     screenisopen = 0;        
  269. }    
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279. int HandlemgetIDCMP( struct IntuiMessage * overRideMsg )
  280. {
  281.     struct IntuiMessage    *m;
  282.     struct MenuItem        *n;
  283.     int            (*func)();
  284.     int     index1, index2, nMoveIncrement = 1;
  285.     BOOL            running = TRUE, BMoveTopBottom = FALSE, BLeaveNow = FALSE;
  286.     WORD        wtop = -1 , wleft = -1, wheight = -1 , wwidth= -1;
  287.     
  288.     struct NewGadget ng;
  289.     struct Gadget    *g;
  290.     int FilesWindowHeightLines = nTopListHeight/(listfont.ta_YSize);
  291.     int GetWindowHeightLines = nBottomListHeight/(listfont.ta_YSize)-2;
  292.     int nTemp;
  293.     
  294.     if (GetWindowHeightLines < 1) GetWindowHeightLines = 1;  /* a little less due to round-off error in Gadget */
  295.     
  296.     if (overRideMsg == NULL) m = GT_GetIMsg(mgetWnd->UserPort);
  297.                 else m = overRideMsg;
  298.  
  299.     while( m ) {
  300.  
  301.         CopyMem(( char * )m, ( char * )&mgetMsg, (long)sizeof( struct IntuiMessage ));
  302.         lastcode = m->Code;
  303.         
  304.         GT_ReplyIMsg( m );
  305.  
  306.         if ((mgetMsg.Qualifier & IEQUALIFIER_LSHIFT)||
  307.              (mgetMsg.Qualifier & IEQUALIFIER_RSHIFT)) nMoveIncrement = FilesWindowHeightLines;
  308.              
  309.         if (mgetMsg.Qualifier & IEQUALIFIER_CONTROL)  nMoveIncrement = 10;
  310.         
  311.         if ((mgetMsg.Qualifier & IEQUALIFIER_LALT)||
  312.             (mgetMsg.Qualifier & IEQUALIFIER_RALT)) BMoveTopBottom = TRUE;
  313.         
  314.         switch ( mgetMsg.Class ) {
  315.             case IDCMP_RAWKEY:
  316.                 /* printf("[%i:%c]\n", mgetMsg.Code, mgetMsg.Code); */
  317.                     
  318.                 if (BMoveTopBottom == FALSE)            
  319.                 {
  320.                     switch ( mgetMsg.Code ) {
  321.                         case UP_KEYCODE:
  322.                             nTemp = ListViewTop((struct Gadget *) mgetGadgets[0], filelist);
  323.                             if (nTemp > (nMoveIncrement-1)) nTemp -= nMoveIncrement; else nTemp = 0;
  324.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, nTemp, TAG_END);                
  325.                             break;
  326.                         
  327.                         case DOWN_KEYCODE:
  328.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, 
  329.                                      ListViewTop((struct Gadget *) mgetGadgets[0], filelist) + nMoveIncrement, TAG_END);                
  330.                             break;
  331.                         
  332.                         case LEFT_KEYCODE:
  333.                             nTemp = ListViewTop((struct Gadget *) mgetGadgets[1], getlist);
  334.                             if (nMoveIncrement == FilesWindowHeightLines) nMoveIncrement = GetWindowHeightLines;
  335.                             if (nTemp > (nMoveIncrement-1)) nTemp -= nMoveIncrement; else nTemp = 0;
  336.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[1], mgetWnd, NULL, GTLV_Top, nTemp, TAG_END);                
  337.                             break;
  338.         
  339.                         case RIGHT_KEYCODE:
  340.                             if (nMoveIncrement == FilesWindowHeightLines) nMoveIncrement = GetWindowHeightLines;
  341.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[1], mgetWnd, NULL, GTLV_Top, 
  342.                                                      ListViewTop((struct Gadget *) mgetGadgets[1], getlist) + nMoveIncrement
  343.                                                         , TAG_END);                
  344.                             break;                
  345.                         }
  346.                 }
  347.                 else
  348.                 {
  349.                     /* ALT held down--go to top or bottom of appropriate list */
  350.                     switch ( mgetMsg.Code ) {
  351.                         case UP_KEYCODE:
  352.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, 0, TAG_END);                
  353.                             break;
  354.  
  355.                         case DOWN_KEYCODE:
  356.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, filelist_length, TAG_END);    
  357.                             break;
  358.  
  359.                         case LEFT_KEYCODE:
  360.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[1], mgetWnd, NULL, GTLV_Top, 0, TAG_END);                
  361.                             break;
  362.  
  363.                         case RIGHT_KEYCODE:
  364.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[1], mgetWnd, NULL, GTLV_Top, getlist_length, TAG_END);
  365.                             break;
  366.                     }
  367.                 }
  368.                 break;
  369.                 
  370.             case IDCMP_VANILLAKEY:
  371.                 /* printf("{%i:%c}\n", mgetMsg.Code, mgetMsg.Code); */
  372.                                 
  373.                 switch ( mgetMsg.Code ) {
  374.                     case ' ':
  375.                         GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, 
  376.                             ListViewTop((struct Gadget *) mgetGadgets[0], filelist) + FilesWindowHeightLines, TAG_END);
  377.                     break;
  378.                     
  379.                     case BACKSPACE_KEYCODE:
  380.                         nTemp = ListViewTop((struct Gadget *) mgetGadgets[0], filelist) - FilesWindowHeightLines;
  381.                         if (nTemp < 0) nTemp = 0;
  382.                         GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, nTemp, TAG_END);                
  383.                     break;                    
  384.                 }
  385.                 break;
  386.                 
  387.             case IDCMP_REFRESHWINDOW:
  388.                 GT_BeginRefresh( mgetWnd );
  389.                 GT_EndRefresh( mgetWnd, TRUE );
  390.                 break;
  391.  
  392.             case IDCMP_NEWSIZE:
  393.                 windowtop = mgetWnd->TopEdge;
  394.                 windowleft = mgetWnd->LeftEdge;
  395.                 windowheight = mgetWnd->Height;
  396.                 windowwidth = mgetWnd->Width;
  397.                 
  398.                 index1 = ListViewTop ((struct Gadget *) mgetGadgets[0], mgetWnd);
  399.                 index2 = ListViewTop ((struct Gadget *) mgetGadgets[1], mgetWnd);
  400.  
  401.                 RemoveGList(mgetWnd, mgetGList, -1);
  402.                 FreeGadgets(mgetGList);
  403.                 
  404.                 EraseRect(mgetWnd->RPort,mgetWnd->BorderLeft, mgetWnd->BorderTop,
  405.                             mgetWnd->Width - mgetWnd->BorderRight - 1,
  406.                             mgetWnd->Height - mgetWnd->BorderBottom - 1);
  407.                             
  408.                 if (SetupGadgets(g, &ng) == 2L) 
  409.                     {
  410.                     MakeReq("ListView Gadget Setup Error",NULL,"I wish Jeremy would debug better");
  411.                     CleanUp();
  412.                     exit(10);
  413.                     }
  414.                 AddGList(mgetWnd, mgetGList, -1, -1, NULL);
  415.                 RefreshGList(mgetGList, mgetWnd, NULL, -1);
  416.                         
  417.                 GT_RefreshWindow(mgetWnd, NULL);
  418.                 RefreshWindowFrame(mgetWnd);
  419.                 
  420.                 ChangeWindowTitle();                
  421.                 
  422.                 GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, GTLV_Top, index1, TAG_END); 
  423.                 GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, getlist, GTLV_Top, index2, TAG_END); 
  424.                 break;
  425.                 
  426.             case    IDCMP_CLOSEWINDOW:
  427.                 running = mgetCloseWindow();
  428.                 break;
  429.  
  430.             case    IDCMP_GADGETUP:
  431.             case    IDCMP_GADGETDOWN:
  432.                 func = ( void * )(( struct Gadget * )mgetMsg.IAddress )->UserData;
  433.                 running = func();
  434.                 break;
  435.  
  436.             case    IDCMP_MENUPICK:
  437.                 while( mgetMsg.Code != MENUNULL ) {
  438.                     n = ItemAddress( mgetMenus, mgetMsg.Code );
  439.                     func = (void *)(GTMENUITEM_USERDATA( n ));
  440.                     if (func == (int(*)()) &mgeticonify) BLeaveNow = TRUE;
  441.                     running = func();
  442.                     if (BLeaveNow == FALSE) mgetMsg.Code = n->NextSelect; else mgetMsg.Code = MENUNULL;
  443.                 }
  444.                 break;
  445.         }
  446.         if (BLeaveNow == FALSE) m = GT_GetIMsg( mgetWnd->UserPort ); else m = NULL;
  447.     }
  448.     return( running );
  449. }
  450.  
  451.  
  452.  
  453.  
  454.  
  455. int SetupGadgets(struct Gadget *gadlist, struct NewGadget *ng)
  456. {
  457.  UWORD        lc, tc;
  458.  UWORD        offx = Scr->WBorLeft, offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  459.  UWORD        wheight = windowheight - offy;
  460.  UWORD        wwidth  = windowwidth  - offx;
  461.  UWORD        topedge[2], height[2];
  462.  BYTE           bSizeGadHeight = 8;        
  463.  struct List      *thislist = NULL; 
  464.            
  465.  topedge[0]    = offy;
  466.  height[0]     = ((int) (.7 * wheight));
  467.  topedge[1]    = topedge[0] + height[0] + 1;
  468.  height[1]     = windowheight - topedge[1] - bSizeGadHeight - 2;
  469.  
  470.   /* rearrange sizes if height of lower list is too small */
  471.   if (height[1] < nListFontSize * 3)
  472.   {
  473.       height[1] = nListFontSize * 3;
  474.       topedge[1] = windowheight - height[1] - bSizeGadHeight - 2;
  475.       height[0] = topedge[1] - topedge[0];
  476.   }
  477.     
  478.            
  479.   nTopListTop = topedge[0];
  480.   nTopListHeight = height[0];
  481.   nBottomListHeight = height[1];
  482.  
  483.  
  484.   if ( ! ( gadlist = CreateContext( &mgetGList ))) return( 1L );
  485.  
  486.   for( lc = 0, tc = 0; lc < mget_CNT; lc++ ) 
  487.   {    
  488.      if (lc == 1) thislist = getlist; else thislist = filelist;
  489.             
  490.      CopyMem((char * )&mgetNGad[ lc ], (char * )ng, (long)sizeof( struct NewGadget ));
  491.  
  492.      ng->ng_VisualInfo = VisualInfo;
  493.      ng->ng_TextAttr   = &listfont;
  494.      ng->ng_LeftEdge   = offx;
  495.      ng->ng_TopEdge    = topedge[lc];
  496.      ng->ng_Width      = wwidth - offx;
  497.      ng->ng_Height     = height[lc];    
  498.      ng->ng_GadgetText = NULL;
  499.      ng->ng_Flags      = NULL;
  500.      ng->ng_GadgetID   = lc + 50;
  501.  
  502.      mgetGadgets[ lc ] = gadlist = CreateGadget(LISTVIEW_KIND, gadlist, ng, GTLV_Top, 0, TAG_END);
  503.     
  504.      while( mgetGTags[ tc ] ) tc += 2;
  505.  
  506.      tc++;
  507.  
  508.      if ( NOT gadlist) return( 2L );
  509.   }
  510. }
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520. int OpenmgetWindow( void)
  521. {
  522.     struct NewGadget ng;
  523.     struct Gadget    *g;
  524.     int titleheight = (Scr->WBorTop + Scr->RastPort.TxHeight + 1);
  525.     int nMinHeight;
  526.  
  527.      /* Put in correct font */
  528.      listfont.ta_Name  = sListFontName;
  529.      if (nListFontSize > 0) listfont.ta_YSize = nListFontSize; else listfont.ta_YSize = 12;
  530.  
  531.      /* a reasonable default, hopefully! */
  532.      listfontdata = OpenDiskFont(&listfont);    
  533.      if (listfontdata == NULL)
  534.      {
  535.          /* load system default font */
  536.         AskFont(&Scr->RastPort,&listfont);
  537.         listfontdata = OpenDiskFont(&listfont);
  538.         if (listfontdata == NULL)
  539.         {
  540.             CleanUp();
  541.             exit(5);
  542.         }
  543.         if (strlen(sListFontName) > 0) 
  544.         {
  545.             MakeReq("Couldn't find specified font, Sorry!",NULL,"Um, Ok");
  546.             strncpy(sListFontName,NUL,1);
  547.             nListFontSize = listfont.ta_YSize;
  548.         }
  549.     }    
  550.     if (nListFontSize == 0) nListFontSize = listfont.ta_YSize;    /* get default setting */
  551.     
  552.     nMinHeight = (8 * (nListFontSize + 2));
  553.     if (nMinHeight < 90) nMinHeight = 90;
  554.     nMinHeight += titleheight;
  555.   
  556.     if ((windowwidth <= 0)||(windowwidth > screenwidth)) windowwidth  = screenwidth;
  557.     if (windowheight < nMinHeight) windowheight = nMinHeight;
  558.     
  559.     if ((windowheight <= 0)||(windowheight > screenheight)) windowheight = screenheight - titleheight;
  560.             
  561.     if ((windowleft <= 0)||(windowleft > screenwidth))        windowleft   = 0;
  562.     if ((windowleft+windowwidth) > screenwidth)    windowwidth -= windowleft;
  563.     if ((windowtop <= 0)||(windowtop > screenheight))       windowtop    = titleheight;
  564.     if ((windowtop+windowheight) > screenheight) windowheight -= windowtop;
  565.         
  566.     if ((windowwidth <= 0)||(windowwidth > screenwidth))    
  567.         {
  568.         windowwidth  = screenwidth;
  569.         windowleft = 0;
  570.         }
  571.         
  572.     if ((windowheight <= 0)||(windowheight > screenheight)) 
  573.         {
  574.         windowheight = screenheight - titleheight;
  575.         windowtop = titleheight;
  576.         }
  577.         
  578.     
  579.     if (SetupGadgets(g, &ng) == 2L) return(2L);    
  580.     
  581.     if ( ! ( mgetMenus = CreateMenus( mgetNewMenu, GTMN_FrontPen, 0L, TAG_DONE )))
  582.         return( 3L );
  583.     
  584.     LayoutMenus( mgetMenus, VisualInfo, TAG_DONE );    
  585.         
  586.     if (nPrevLeft > 0)
  587.     {
  588.         /* If non-negative, these were the pre-iconify values */
  589.         windowleft = nPrevLeft; 
  590.         windowtop = nPrevTop; 
  591.         windowwidth = nPrevWidth;
  592.         windowheight = nPrevHeight;
  593.     }
  594.     
  595.     
  596.     switch (screentype)
  597.         {
  598.         case USE_PUBSCREEN:
  599.             if ( ! ( mgetWnd = OpenWindowTags( NULL,
  600.                 WA_Left,    windowleft,
  601.                 WA_Top,        windowtop,
  602.                 WA_Width,    windowwidth,
  603.                 WA_Height,    windowheight,
  604.                 WA_PubScreen,    Scr,
  605.                 WA_PubScreenFallBack, TRUE,
  606.                 WA_IDCMP,    LISTVIEWIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_NEWSIZE|IDCMP_RAWKEY|IDCMP_VANILLAKEY,
  607.                 WA_Flags,    WFLG_SIZEGADGET|WFLG_SIZEBBOTTOM|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_NEWLOOKMENUS,
  608.                 WA_Gadgets,    mgetGList,
  609.                 WA_Title,    windowtitle,
  610.                 WA_ScreenTitle,pnamestring,
  611.                 WA_MinWidth,    155,
  612.                 WA_MinHeight,    nMinHeight,
  613.                 WA_MaxWidth,    -1,
  614.                 WA_MaxHeight,    -1,
  615.                 TAG_DONE )))    
  616.                     return( 4L );
  617.             break;
  618.             
  619.         case USE_CUSTOMSCREEN:
  620.             if ( ! ( mgetWnd = OpenWindowTags( NULL,
  621.                 WA_Left,    windowleft,
  622.                 WA_Top,        windowtop,
  623.                 WA_Width,    windowwidth,
  624.                 WA_Height,    windowheight,
  625.                 WA_CustomScreen,Scr,
  626.                 WA_IDCMP,    LISTVIEWIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_NEWSIZE|IDCMP_RAWKEY|IDCMP_VANILLAKEY,
  627.                 WA_Flags,    WFLG_SIZEGADGET|WFLG_SIZEBBOTTOM|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_NEWLOOKMENUS|WFLG_NEWLOOKMENUS|WFLG_NEWLOOKMENUS|WFLG_NEWLOOKMENUS,
  628.                 WA_Gadgets,    mgetGList,
  629.                 WA_Title,    windowtitle,
  630.                 WA_ScreenTitle,pnamestring,
  631.                 WA_MinWidth,    155,
  632.                 WA_MinHeight,    nMinHeight,
  633.                 WA_MaxWidth,    -1,
  634.                 WA_MaxHeight,    -1,
  635.                 TAG_DONE )))    
  636.                     return( 4L );
  637.             break;
  638.             
  639.         case USE_WBSCREEN:
  640.             if ( ! ( mgetWnd = OpenWindowTags( NULL,
  641.                 WA_Left,    windowleft,
  642.                 WA_Top,        windowtop,
  643.                 WA_Width,    windowwidth,
  644.                 WA_Height,    windowheight,
  645.                 WA_IDCMP,    LISTVIEWIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_NEWSIZE|IDCMP_RAWKEY|IDCMP_VANILLAKEY,
  646.                 WA_Flags,    WFLG_SIZEGADGET|WFLG_SIZEBBOTTOM|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_NEWLOOKMENUS,
  647.                 WA_Gadgets,    mgetGList,
  648.                 WA_Title,    windowtitle,
  649.                 WA_ScreenTitle,pnamestring,
  650.                 WA_MinWidth,    155,
  651.                 WA_MinHeight,    nMinHeight,
  652.                 WA_MaxWidth,    -1,
  653.                 WA_MaxHeight,    -1,
  654.                 TAG_DONE )))    
  655.                     return( 4L );
  656.                     
  657.             if (appwindow == 1)
  658.             {
  659.                 awport = CreateMsgPort();
  660.                 if (awport == NULL) 
  661.                 {
  662.                     appwindow = 0;
  663.                     return(4L);
  664.                 }
  665.  
  666.                 appwin = AddAppWindow(1, 0, mgetWnd, awport, NULL);
  667.                 
  668.                 if (appwin == NULL) {appwindow = 0;}
  669.                   else appwinsig = 1L << awport->mp_SigBit;
  670.             }    
  671.             break;
  672.         }    
  673.  
  674.     TurnOnAllMenuItems(mgetMenus);
  675.     SetMenuStrip( mgetWnd, mgetMenus ); 
  676.     GT_RefreshWindow( mgetWnd, NULL );
  677.     windowisopen = 1;
  678. return( 0L );
  679. }
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687. void ClosemgetWindow( void )
  688. {
  689.     /* safety first! */
  690.     if (mgetWnd == NULL) return;
  691.     
  692.     /* Save values for de-iconify, maybe */
  693.     nPrevLeft   = mgetWnd->LeftEdge; 
  694.     nPrevTop    = mgetWnd->TopEdge; 
  695.     nPrevWidth  = mgetWnd->Width; 
  696.     nPrevHeight = mgetWnd->Height; 
  697.     
  698.     if ( mgetMenus      ) 
  699.     {
  700.         ClearMenuStrip( mgetWnd );
  701.         FreeMenus( mgetMenus );
  702.         mgetMenus = NULL;    
  703.     }
  704.  
  705.     if ( findwindow     ) 
  706.     { 
  707.          CloseWindow( findwindow );
  708.          FreeGadgets(findgadlist);
  709.          FreeVisualInfo(findvi);
  710.          findwindow = NULL;
  711.     }
  712.      
  713.      if (appwin) 
  714.      {
  715.          RemoveAppWindow(appwin);
  716.          
  717.          /* throw out any leftover messages */
  718.          while(amsg = (struct AppMessage *) GetMsg(awport))
  719.                  ReplyMsg((struct Message *) amsg);
  720.          DeleteMsgPort(awport);
  721.      }
  722.         
  723.     if ( mgetWnd        ) 
  724.     {
  725.         CloseWindow( mgetWnd );
  726.         windowisopen = 0;
  727.         mgetWnd = NULL;
  728.     }
  729.  
  730.     if ( mgetGList      ) 
  731.     {
  732.         FreeGadgets( mgetGList );
  733.         mgetGList = NULL;
  734.     }
  735. }
  736.  
  737.  
  738. #endif
  739.  
  740.